//
//  DoorLockControlViewController.m
//  SouthKoreaDoorLock
//
//  Created by Umeinfo on 2018/1/15.
//  Copyright © 2018年 andy90s. All rights reserved.
//

#import "DoorLockControlViewController.h"
#import "SKSwitch.h"

@interface DoorLockControlViewController ()

@property (nonatomic, strong) UIButton *doorLockButton;
@property (nonatomic, strong) SKSwitch *doorLockSwitch;
@property (nonatomic, strong) SKSwitch *statusSwitch;
@property (nonatomic, strong) UIImageView *lockStatusImage;
@property (nonatomic, strong) UIImageView *batteryStatusImage;

@end

@implementation DoorLockControlViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
    
}

- (void)setupViews {
    self.title = SKLANGUAGE(@"DOOR_LOCK_CONTROL_CONTROL");
    [self.view addSubview:self.doorLockButton];
    [self.doorLockButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(70);
        make.width.offset(50);
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.navigationBar.mas_bottom).offset(30);
    }];
    
    // tips.
    UILabel *doorTipLab = [UILabel new];
    doorTipLab.font = [UIFont systemFontOfSize:24];
    doorTipLab.text = SKLANGUAGE(@"DOOR_LOCK_CONTROL_DOOR_LOCK_STATUS");
    doorTipLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:doorTipLab];
    [doorTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.equalTo(self.view);
        make.height.offset(25);
        make.top.equalTo(self.doorLockButton.mas_bottom).offset(25);
    }];
    // lock & unlock Swtich.
    [self.view addSubview:self.doorLockSwitch];
    [self.doorLockSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.offset(300);
        make.height.offset(30);
        make.top.equalTo(doorTipLab.mas_bottom).offset(25);
    }];
    
    // lock & battery status.
    UIView *helpLine = [UIView new];
    [self.view addSubview:helpLine];
    [helpLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.width.offset(1);
        make.height.offset(100);
    }];
    
    [self.view addSubview:self.lockStatusImage];
    [self.lockStatusImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(self.view.bounds.size.width / 2 - 50);
        make.top.equalTo(self.doorLockSwitch.mas_bottom).offset(50);
        make.right.equalTo(helpLine.mas_left).offset( -10);
    }];
    
    [self.view addSubview:self.batteryStatusImage];
    [self.batteryStatusImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(self.view.bounds.size.width / 2 - 50);
        make.centerY.equalTo(self.lockStatusImage);
        make.left.equalTo(helpLine.mas_right).offset(20);
    }];
    
    UILabel *lockImageLab = [UILabel new];
    lockImageLab.textAlignment = NSTextAlignmentCenter;
    lockImageLab.text = SKLANGUAGE(@"DOOR_LOCK_CONTROL_LOCK_STATUS");
    [self.view addSubview:lockImageLab];
    [lockImageLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.lockStatusImage);
        make.bottom.equalTo(self.lockStatusImage.mas_top).offset(-10);
    }];
    
    UILabel *batteryLab = [UILabel new];
    batteryLab.textAlignment = NSTextAlignmentCenter;
    batteryLab.text = SKLANGUAGE(@"DOOR_LOCK_CONTROL_BATTERY_STATUS");
    [self.view addSubview:batteryLab];
    [batteryLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.batteryStatusImage);
        make.bottom.equalTo(self.batteryStatusImage.mas_top).offset(-10);
    }];
    
    // status switch
    [self.view addSubview:self.statusSwitch];
    [self.statusSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.offset(300);
        make.height.offset(30);
        make.top.equalTo(self.batteryStatusImage.mas_bottom).offset(80);
    }];
    UILabel *statusTipLab = [UILabel new];
    statusTipLab.textAlignment = NSTextAlignmentCenter;
    statusTipLab.text = SKLANGUAGE(@"DOOR_LOCK_CONTROL_GUARD_STATUS");
    [self.view addSubview:statusTipLab];
    [statusTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.statusSwitch);
        make.bottom.equalTo(self.statusSwitch.mas_top).offset(-30);
    }];
}

// refresh touch.
- (void)rightNavItemClick {
    
}

#pragma mark - lazy

- (UIButton *)doorLockButton {
    if (!_doorLockButton) {
        _doorLockButton = [UIButton new];
//        [_doorLockButton setImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
        //[_doorLockButton setImage:[UIImage imageNamed:@"door_icon_lock"] forState:UIControlStateNormal];
        [_doorLockButton setBackgroundImage:[UIImage imageNamed:@"door_icon_lock"] forState:UIControlStateNormal];
    }
    return _doorLockButton;
}

- (SKSwitch *)doorLockSwitch {
    if (!_doorLockSwitch) {
        _doorLockSwitch = [SKSwitch new];
        _doorLockSwitch.titles = @[SKLANGUAGE(@"DOOR_LOCK_CONTROL_LOCK"),SKLANGUAGE(@"DOOR_LOCK_CONTROL_UNLOCK")];
        _doorLockSwitch.backIconName = @"settingbox";
    }
    return _doorLockSwitch;
}

- (SKSwitch *)statusSwitch {
    if (!_statusSwitch) {
        _statusSwitch = [SKSwitch new];
        _statusSwitch.titles = @[SKLANGUAGE(@"DOOR_LOCK_CONTROL_ON"),SKLANGUAGE(@"DOOR_LOCK_CONTROL_OFF")];
        _statusSwitch.backIconName = @"guard_settingbox";
    }
    return _statusSwitch;
}

- (UIImageView *)lockStatusImage {
    if (!_lockStatusImage) {
        _lockStatusImage = [UIImageView new];
        _lockStatusImage.image = [UIImage imageNamed:@"lockstatuse_locked"];
    }
    return _lockStatusImage;
}

- (UIImageView *)batteryStatusImage {
    if (!_batteryStatusImage) {
        _batteryStatusImage = [UIImageView new];
        _batteryStatusImage.image = [UIImage imageNamed:@"bat_5"];
    }
    return _batteryStatusImage;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
